Socket
Socket
Sign inDemoInstall

@types/node-forge

Package Overview
Dependencies
2
Maintainers
1
Versions
72
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @types/node-forge

TypeScript definitions for node-forge


Version published
Weekly downloads
6.6M
increased by0.86%
Maintainers
1
Created
Weekly downloads
 

Package description

What is @types/node-forge?

@types/node-forge provides TypeScript type definitions for the node-forge library, which is a native implementation of TLS (and various other cryptographic tools) in JavaScript. It allows developers to perform a variety of cryptographic operations such as encryption, decryption, hashing, and digital signatures.

What are @types/node-forge's main functionalities?

Encryption and Decryption

This feature allows you to encrypt and decrypt data using the AES-CBC algorithm. The code sample demonstrates how to encrypt a simple 'Hello World' string and then decrypt it back to its original form.

const forge = require('node-forge');
const key = forge.random.getBytesSync(16);
const iv = forge.random.getBytesSync(16);
const cipher = forge.cipher.createCipher('AES-CBC', key);
cipher.start({iv: iv});
cipher.update(forge.util.createBuffer('Hello World'));
cipher.finish();
const encrypted = cipher.output;
const decipher = forge.cipher.createDecipher('AES-CBC', key);
decipher.start({iv: iv});
decipher.update(encrypted);
decipher.finish();
const decrypted = decipher.output.toString();
console.log(decrypted);

Hashing

This feature allows you to create cryptographic hashes using various algorithms like SHA-256. The code sample demonstrates how to hash a 'Hello World' string using SHA-256.

const forge = require('node-forge');
const md = forge.md.sha256.create();
md.update('Hello World', 'utf8');
const hash = md.digest().toHex();
console.log(hash);

Digital Signatures

This feature allows you to create and verify digital signatures. The code sample demonstrates how to sign a 'Hello World' string with a private key and then verify the signature with the corresponding public key.

const forge = require('node-forge');
const pki = forge.pki;
const keys = pki.rsa.generateKeyPair(2048);
const md = forge.md.sha256.create();
md.update('Hello World', 'utf8');
const signature = keys.privateKey.sign(md);
const verified = keys.publicKey.verify(md.digest().bytes(), signature);
console.log(verified);

TLS/SSL

This feature allows you to create and manage TLS/SSL certificates. The code sample demonstrates how to generate a self-signed certificate.

const forge = require('node-forge');
const pki = forge.pki;
const keys = pki.rsa.generateKeyPair(2048);
const cert = pki.createCertificate();
cert.publicKey = keys.publicKey;
cert.serialNumber = '01';
cert.validity.notBefore = new Date();
cert.validity.notAfter = new Date();
cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 1);
const attrs = [{name: 'commonName', value: 'example.org'}];
cert.setSubject(attrs);
cert.setIssuer(attrs);
cert.sign(keys.privateKey);
const pem = pki.certificateToPem(cert);
console.log(pem);

Other packages similar to @types/node-forge

Readme

Source

Installation

npm install --save @types/node-forge

Summary

This package contains type definitions for node-forge (https://github.com/digitalbazaar/forge).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node-forge.

Additional Details

  • Last updated: Tue, 02 Jan 2024 22:35:21 GMT
  • Dependencies: @types/node

Credits

These definitions were written by Seth Westphal , Kay Schecker , Aakash Goenka , Rafal2228 , Beeno Tung , Joe Flateau , timhwang21 , Anders Kaseorg , Sascha Zarhuber , Rogier Schouten , Ivan Aseev , Wiktor Kwapisiewicz, Ligia Frangello , Dmitry Avezov , Jose Fuentes , Anya Reyes , and BendingBender .

FAQs

Last updated on 02 Jan 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc